import { defineStore } from "pinia";
import { ref, computed } from "vue";

export const useCounterStore = defineStore("CounterStore", () => {
	// 定义一个数据，相当于state
	const count = ref(0);
	// 相当于getters
	const doubleCount = computed(() => {
		return count.value * 2;
	});
	// 相当于mutations
	function increment() {
		count.value++;
	}
	return {
		count,
		doubleCount,
		increment,
	};
});

// 另一种仓库写法
/* export const useCounterStore = defineStore("countStore", {
	state: () => {
		return {
			count: 0,
		};
	},
	getters: {
		doubleCount: (state) => {
			return state.count * 2;
		},
	},
	actions: {
		increment() {
			this.count++;
		},
	},
}); */
